﻿<!DOCTYPE html>
<!--管理制度--填加-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>

    <meta charset="utf-8" />
    <title></title>
</head>

<body>
    <div id="app" class="popupW100" v-cloak>
        <!-- class="popupW100"为label宽度为100px，共有popupW50、popupW100、popupW150、popupW200可选 -->
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            size="mini">

            <el-row>

                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="mS_InstitutionName">
                            <el-input type="text" v-model="Form.mS_InstitutionName" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    <!--文件编号-->
                                    {{ManagementSystem.MS_InstitutionName+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.mS_InstitutionName">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item prop="mS_FileNo">
                            <el-input type="text" v-model="Form.mS_FileNo" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    <!--文件编号-->
                                    {{ManagementSystem.MS_FileNo+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.mS_FileNo">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>

            </el-row>
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="fileLeve">
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{ManagementSystem.MS_Sort+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.fileLeve" slot="suffix" :placeholder="ManagementSystem.MS_Sort">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in FL_SystemFileLevel" :label="item.fileLeve" :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.fileLeve">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item prop="mS_ImplementationDate">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{ManagementSystem.MS_ImplementationDate+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.mS_ImplementationDate" type="date"
                                                size="mini" format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择实施日期">
                                </el-date-picker>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.mS_ImplementationDate">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="mS_ReviewCycle">
                            <el-input type="text" v-model="Form.mS_ReviewCycle" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    <!--文件编号-->
                                    {{ManagementSystem.Dycle+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.mS_ReviewCycle">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <el-form-item prop="mS_ReviewDate">
                        <div class="elst-select-mini" >
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{ManagementSystem.MS_ReviewDate+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.mS_ReviewDate" type="date" size="mini"
                                                format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择评审日期">
                                </el-date-picker>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.mS_ReviewDate">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </div>
                    </el-form-item>
                </el-col>
                <el-col :span="11">
                    <el-form-item prop="mS_RevisionTime">
                        <div class="elst-select-mini" >
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{ManagementSystem.MS_RevisionDate+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.mS_RevisionTime" type="date" size="mini"
                                                format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="选择修订日期">
                                </el-date-picker>
                            </el-input>
                        </div>
                    </el-form-item>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item prop="MS_Mark">
                            <el-input type="text" v-model="Form.mS_Mark" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    <!--文件编号-->
                                    {{ManagementSystem.MS_Mark+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item prop="attachment">

                            <label for="Trainingtime" class="el-form-item__label"
                                   style="width: 150px;">{{LawRegulationsInput.Attachment+mark.m}}</label>

                            <span>
                                <btn-uploadfile-input v-model="Form.attachmentName" text="上传附件"
                                                      :fileid="Form.attachment" :filename="Form.attachmentName" :showdownload="true"
                                                      @success="attachmentHandle"></btn-uploadfile-input>

                            </span>
                        </el-form-item>
                    </div>

                    <!--上报部门-->
                </el-col>
                <el-col :span="24">
                    <div class="elst-select-mini vue-treeselect_style">
                        <el-form-item prop="departmentId1">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{LawRegulationsTable.BelongToClass+mark.m}}
                                </template>
                                <!--<tree-department v-model="Form.BelongToClass" :value="Form.BelongToClass"
        :multiple="true" :flat="true" :show-count="true" :disable-branch-nodes="true"
        slot="suffix" style="line-height:14px;" placeholder="请选择" />-->
                                <treeselect v-model="Form.departmentId1" :options="department" :multiple="false"
                                            :show-count="true" :disable-branch-nodes="false" slot="suffix"
                                            style="line-height: 20px;" placeholder="请选择" />
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.departmentId1">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <br />
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>
                    <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>-->
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>

            </el-row>
        </el-form>
    </div>
    <script type="text/javascript">
        var uploadText = "请选择上传文件";
        Vue.component('treeselect', VueTreeselect.Treeselect)
        //var gutid = gutid();//取随机主键
        //function gutid() {
        //    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        //        var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        //        return v.toString(16);
        //    });
        //};

        //取序号
      //  var gunstN = parent.$ManagementSystem.Arrays.length
        //var gutNum = gunstN + 1;


        //var gutNum = gutNum();
        //function gutNum() {
        //    ufoiNum = ufoiNum + 1;
        //    return ufoiNum;
        //};




        var app = new Vue({
            el: '#app',
            data: {
                ListItem1: {
                    //tableDate: {
                    tablebox1: [],
                    //},
                },
                formInline: {
                    model: {
                        createFactory: null,
                        //   Attachment: ''
                    },
                    offset: 0,
                    limit: 10
                },
                //父业传参
                id: '',
                show: '',
                FL_SystemFileLevel: [],
                department: [],
                //获取下拉菜单sex
                // sex: [],
                //业务表单内容
                Form: {
                    fileLeve: '',
                    //id: guidEmpty,
                    id: guidEmpty,
                    // MS_Id: gutNum, // '999999',
                    MS_Id: '',
                    mS_institutionName: '',
                    mS_FileNo: '',
                    MS_Sort: '',
                    LBSorts: '',
                    Dycle: '',
                    MS_ReviewDate: '',
                    MS_ImplementationDate: '',
                    attachment: '',
                    attachmentName: '',
                    IsHSE: '',  //是否是HSE类别
                    RDepartments: '',//相关部门
                    multiple: true,
                    Department: [],
                    departmentId1: null,
                    FL_SystemDept: [],
                    MS_ReviewCycle: '',
                    MS_RevisionTime: '',
                },
              //  LBSorts: [],
              //  IsHSE: [],
              //  RDepartments: [],
                //表单验证
                rules: {
                    mS_InstitutionName: [
                        verification.NotNull
                    ],
                    mS_FileNo: [
                        verification.NotNull
                    ],
                    //MS_Sort: [
                    //    verification.NotNull,
                    //],
                    //MS_IsHSE: [
                    //    verification.NotNull,
                    //],
                    mS_ReviewCycle: [
                        verification.NotNull,
                    ],
                    mS_ImplementationDate: [
                        verification.NotNull,
                    ],
                    mS_ReviewDate: [
                        verification.NotNull,
                    ],
                    mS_RelevantDepartments: [
                        verification.NotNull,
                    ],
                    fileLeve: [
                        verification.NotNull,
                    ],
                    //归口部门                    
                    departmentId1: [
                        verification.NotNull
                    ],

                },
                //IsCAM_Compliance: [],

            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //初始化部门下拉树
                getDepartmentData: function () {
                    var mythis = this;
                    //获取工厂ID
                    myAjax("post", mythis, '/api/FL_StandardInformationWeb/getFactory', { model: {}, offset: 0, limit: 10 }, function (response) {
                        console.log('response.data.pageData', response.data.pageData)
                        mythis.ListItem1.tablebox1 = response.data;
                     //   alert(mythis.ListItem1.tablebox1.createFactory);

                        myAjax("post", this, '/api/SysDepartment/GetList', { model: { Name: '', Code: '', CreateFactory: mythis.ListItem1.tablebox1.createFactory }, offset: 0, limit: 10 }, function (response) {
                        mythis.department = menuHelperX(response.data.pageData, guidEmpty)
                        }, false);
                    });
                },
                attachmentHandle: function (response, fileid, fileName) {

                    console.log('fileid', fileid)
                    console.log('fileName', fileName)

                    this.Form.attachment = fileid;
                    this.Form.attachmentName = fileName;

                    console.log(' this.Form.attachment', this.Form.attachment)
                    console.log(' this.Form.attachmentName', this.Form.attachmentName)

                },
                handleRemove: function (file) {
                    console.log(file);
                },
                handlePreview: function (file) {
                    console.log(file.name);
                    window.open(file.url)
                },
                //上传附件文件的校验
                //CoursewareUploadbeforeupload: function (file) {
                //    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                //    //将附件名赋值到label上
                //    this.Form.MS_InstitutionName = file.name;
                //    const extension = testmsg === 'doc'
                //    const extension2 = testmsg === 'pdf'
                //    const isLt10M = file.size / 1024 / 1024 < 10
                //    if (!extension && !extension2) {
                //        this.$message({
                //            message: '上传文件只能是 doc、pdf格式!',
                //            type: 'warning'
                //        });
                //    }
                //    if (!isLt10M) {
                //        this.$message({
                //            message: '上传文件大小不能超过 10MB!',
                //            type: 'warning'
                //        });
                //    }
                //    if (extension || extension2 && isLt10M)
                //        submitUpload(this, 'upload')
                //    return extension || extension2 && isLt10M
                //},
                btnAttachmentUpload: function () {
                    //若更换文件则将文件名字更换触发条件--先删除上一个文件,后添加一个文件
                    if (this.fileAttachmentUpload != uploadText) {
                        this.$refs.Attachmentupload.clearFiles();
                        this.fileAttachmentUpload = file.name;
                    }
                    else {

                    }
                    this.$refs.Attachmentupload.submit();
                },

                input: function (value) {
                    this.Form.Department = value;
                },
                //提交数据
                onSubmitForm: function (formName) {
                    //console.log("xxxxx890xxxxxxx");
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            if (mythis.Form.departmentId1) {
                                mythis.Form.FL_SystemDept = [];
                                mythis.Form.FL_SystemDept.push({
                                    DeptId: String(mythis.Form.departmentId1)
                                })
                            }

                            onSubmitForm(this, '/api/FL_System/Save', mythis.Form);
                        } else {
                            //验证失败
                            showMessage(msg.NoMust, 'error');

                            return false;
                        }
                    });
                },
                getData: function () {
                    //console.log("获取编辑数据开始");
                    getData(this, '/api/FL_System/get?id=' + this.id);
                    //this.Form.sex = this.Form.sex + "";
                    //console.log(this.id);
                    //console.log("获取编辑数据结束");
                },
                GetLevelData: function () {
                    var mythis = this;
                    myAjax("post", mythis, '/api/FL_SystemFileLevel/GetList', { model: {}, offset: 0, limit: 10 }, function (response) {
                        mythis.FL_SystemFileLevel = response.data.pageData
                    });
                },
            },
            mounted: function () {
                this.GetLevelData();
                this.getDepartmentData();
                this.id = getUrlParam("id");
             
                this.getData();
              
                if (this.id != null) {
                    this.Form.departmentId1 = [];
                    var mythis = this;
                   
                    mythis.Form.fL_SystemDept.forEach(function (a) {
                        mythis.Form.departmentId1.push(a.deptId);
                    });
                }


              //  //获取下拉菜单内容
              //  //this.sex = getDicData('01');
              //  //console.log(id);
              //  //console.log(parent.$LawRegulationsTable.Arrays.length);
              //  //console.log(this.getData());


              ////  var list = getDicDataArray(['105']);
              ////  this.IsCAM_Compliance = getDicDatafromArray('105', list);//符合情况
              //  console.log("xxxxxxxxxxxxxxxxxxxxx");
              //  console.log(this.IsCAM_Compliance);
              //  console.log("xxxxxxxxxxxxxxxxxxxxx");
              ////  this.LBSorts = getDicData('65');
              ////  this.IsHSE = getDicData('50');
              // // this.RDepartments = getDicData('67');

              //  console.log("hhhhhhhhhhhhhh");
              //  console.log(this.id = getUrlParam("id"));
              //  console.log("hhhhhhhhhhhhhh");

              //  if (this.id == null) {
              //      //$("#stt1div").show();
              //      //$("#stt2div").show();

              //      $("#stt1div").css("display", "block");
              //      $("#stt2div").css("display", "block");
              //      console.log("shwwwwwwwwww");
              //  }
              //  else {
              //      //$("#stt1div").hide();
              //      //$("#stt2div").hide();
              //      $("#stt1div").css("display", "none");
              //      $("#stt2div").css("display", "none");


              //      console.log("hideeeeeeeeeee");
              //  };
              //  //if (this.Form.Attachment == '') {
              //  //    this.show = false
              //  //} else {
              //  //    this.show = true
              //  //};

            }
        });
        //下拉树数据格式化
        function menuHelperX(list, pid) {
            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }
                temp.label = v.name;
                temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
                var obj;
                if (temp.parentId == pid) {
                    obj = temp;
                    var nextObj = menuHelperX(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>